package com.qf.weektest.util;

import com.qf.weektest.weektest.entity.Tel;
import com.qf.weektest.weektest.service.ITelService;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;
import java.io.UnsupportedEncodingException;

public class GetCookieByTel {

    public static String newCookieByTel(String telephone,  HttpServletResponse response) throws UnsupportedEncodingException {

        String  token = JWTUtil.getToken(telephone);

        Cookie cookie = new Cookie(telephone, token);

        cookie.setPath("/");

        cookie.setMaxAge(60*60*24*14);

        response.addCookie(cookie);

         return token;
    }
}
